/*
 * Generated file. 
 * 
 * ActionsBar.java
 */
package xsp;

import com.ibm.xsp.page.compiled.AbstractCompiledPage;
import com.ibm.xsp.page.compiled.AbstractCompiledPageDispatcher;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import com.ibm.xsp.page.compiled.NoSuchComponentException;
import com.ibm.xsp.page.compiled.PageExpressionEvaluator;
import java.lang.String;
import com.ibm.xsp.component.UIViewRootEx2;
import java.lang.Boolean;
import com.ibm.xsp.component.UIPanelEx;
import java.util.Map;
import java.lang.Object;
import com.ibm.xsp.component.xp.XspCommandButton;
import javax.faces.el.ValueBinding;
import com.ibm.xsp.component.xp.XspEventHandler;
import javax.faces.el.MethodBinding;

@SuppressWarnings("all")
public class ActionsBar extends AbstractCompiledPageDispatcher{
    
    public ActionsBar() {
        super("8.5.1"); // version of xp:eventHandler execMode
    }

    protected AbstractCompiledPage createPage(int pageIndex) {
        return new ActionsBarPage();
    }
    
    protected boolean isCustomControl() {
        return true;
    }

    public static class ActionsBarPage extends AbstractCompiledPage {
        
        private static final ComponentInfo[] s_infos = new ComponentInfo[]{
            ComponentInfo.EMPTY_NORMAL, // 0 eventHandler
            new ComponentInfo(false, new int[]{0}), // 1 "buttonnewtopic"
            new ComponentInfo(false, new int[]{1}), // 2 panel
            new ComponentInfo(false, new int[]{2}), // 3 view
        };
        
        public ActionsBarPage() {
            super(3, s_infos );
        }
        
        public int getComponentForId(String id) throws NoSuchComponentException { 
            if( "buttonnewtopic".equals(id) )
                return 1;
            return -1;
        }
        
        public UIComponent createComponent(int id, FacesContext context,
                UIComponent parent, PageExpressionEvaluator evaluator)
                throws NoSuchComponentException { 
            switch (id) {
            case 3:
                return createView(context, parent, evaluator);
            case 2:
                return createPanel(context, parent, evaluator);
            case 1:
                return createButtonnewtopic(context, parent, evaluator);
            case 0:
                return createEventHandler(context, parent, evaluator);
            }
            throw new NoSuchComponentException(id);
        }
        
        private UIComponent createView(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            UIViewRootEx2 result = new UIViewRootEx2();
            initViewRoot(result);
            return result;
        }

        private UIComponent createPanel(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            // loaded=??
            String loadedBnd = "#{javascript:getDisplayFormType() == null}";
            String sourceId = "/xp:view[1]/xp:panel[1]/@loaded";
            String loaded = evaluator.evaluateAsString(null, loadedBnd, sourceId, boolean.class);
            if ( null != loaded && loaded.length() > 0 &&
                    ! Boolean.parseBoolean(loaded) ) {
                return null;
            } // else loaded was true
            UIPanelEx result = new UIPanelEx();
            Map<String,Object> attrs = getAttributes(result);
            attrs.put("themeId", "Panel.actionsBar");
            return result;
        }

        private UIComponent createButtonnewtopic(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            XspCommandButton result = new XspCommandButton();
            result.setValue("New Topic");
            String sourceId = "buttonNewTopic/xp:this.rendered[1]/text()";
            String renderedExpr = "#{javascript:userBean.canCreateDocs}";
            ValueBinding rendered = evaluator.createValueBinding(result, renderedExpr, sourceId,boolean.class);
            result.setValueBinding("rendered", rendered);
            setId(result, "buttonNewTopic");
            return result;
        }

        private UIComponent createEventHandler(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            XspEventHandler result = new XspEventHandler();
            result.setImmediate(true);
            result.setExecMode("partial");
            String sourceId = "buttonNewTopic/xp:eventHandler[1]/xp:this.action[1]/text()";
            MethodBinding action = evaluator.createMethodBinding(result,
                    "#{javascript:\n\t\t\t\t\tsetDisplayFormType(1);\n\t\t\t\t\tcontext.reloadPage();\n\t\t\t\t}",
                    null,null, sourceId);
            result.setAction(action);
            result.setSubmit(true);
            result.setEvent("onclick");
            result.setRefreshMode("complete");
            return result;
        }

    }
}
